package serial;

import com.alibaba.fastjson.JSONObject;

import java.io.ByteArrayOutputStream;
import java.io.ObjectOutputStream;
import java.io.UnsupportedEncodingException;

/**
 * protoc-3.6.1-osx-x86_64/bin/protoc --proto_path ./ --java_out ./ msg.proto
 * Created by sunyuming on 19/8/7.
 */
public class SerialMain {
    public static void main(String []f ) throws UnsupportedEncodingException {
        MyBaseProto.BaseProto.Builder builder = MyBaseProto.BaseProto.newBuilder();
        builder.setCode(1);
        builder.setMsg("test");
        byte [] pb = builder.build().toByteArray();
        System.out.println(builder.build().toString());
        System.out.println(pb.length);

        MyBaseBean myBaseBean = new MyBaseBean();
        byte[] bytes = null;
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        try {
            ObjectOutputStream oos = new ObjectOutputStream(bos);
            oos.writeObject(myBaseBean);
            oos.flush();
            bytes = bos.toByteArray ();
            oos.close();
            bos.close();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        System.out.println(bytes.length);

        String json = JSONObject.toJSONString(myBaseBean);
        System.out.println(json);
        System.out.println(json.getBytes("utf-8").length);
    }
}
